<?php
/**
 * Created by PhpStorm.
 * User: qishengqiang
 * Date: 2022-09-26
 * Time: 04:45
 */

namespace app\applet\controller;

use app\applet\BaseController;
use app\models\GdzyzActivities;

class TestController extends BaseController
{
    public function indexAction()
    {
        try {
            //$this->app->gdzyzService->getActivityLists();

            $this->app->weikeyunService->getAccessToken();

            $this->app->weikeyunService->getOrderLists();

            echo '处理成功';die;

        } catch (\Exception $e) {
            return json()->data(['code' => 500, 'msg' => $e->getMessage(), 'data' => [], '1' => $e->getLine(),'2' => $e->getFile()]);
        }
    }

    public function creditAction()
    {
        set_time_limit(0);
        try {
            $activities = GdzyzActivities::where('signStartTime', '<', date('Y-m-d H:i:s', strtotime('-1 hour')))->limit(10)->select();

            if (count($activities)) {
                echo "正在处理中</br>";
                foreach ($activities as $activity) {
                    $this->app->gdzyzService->refreshCode($activity);
                }
            } else {
                echo '处理结束';die();
            }

            sleep(15);

            echo "<script>window.location.href='/applet/test/credit'</script>";

        } catch (\Exception $e) {
            return json()->data(['code' => 500, 'msg' => $e->getMessage(), 'data' => []]);
        }
    }
}